import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
// vue-croppe 插件 头像
import VueCropper from 'vue-cropper'
Vue.use(VueCropper)
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
const { mockXHR } = require('../mock')
mockXHR()
// }
// 动态修改浏览器导航栏图标
const changeFavicon = link => {
  let $favicon = document.querySelector('link[rel="icon"]')
  if ($favicon !== null) {
    $favicon.href = link
  } else {
    $favicon = document.createElement('link')
    $favicon.rel = 'icon'
    $favicon.href = link
    document.head.appendChild($favicon)
  }
}
const iconUrl = 'http://124.223.14.236:7005/' + store.getters.web_ico // 图片地址
changeFavicon(iconUrl) // 动态修改网站图标

// 自定义指令处理按钮权限
Vue.directive('allow', {
  inserted(el, binding) {
    // 从vuex中存储的用户信息中取出当前用户拥有的权限点数组
    const btnList = store.state.user.btnList
    if (btnList.length && btnList[0] === '*') return
    // console.log(el)
    // console.log(binding)
    // 根据binding.value拿到按钮权限标识
    // console.log(binding.value)
    // 如果当前按钮绑定的权限标识不在用户拥有的权限标识数组中就隐藏按钮
    const markList = btnList.map(item => item.permission_mark)
    // console.log(markList)
    if (!markList.includes(binding.value)) {
      el.remove()
    }
  }
})
// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
